package com.weacar.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.weacar.R;
import com.weacar.config.AppStatus;
import com.weacar.utils.AppManager;
import com.weacar.utils.AppStatusManager;

import net.grandcentrix.tray.AppPreferences;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.iv_start_bg)
    ImageView iv_start_bg;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        AppManager.getInstance().addActivity(this);

        // 加载启动图
        AppPreferences appPreferences = new AppPreferences(this);
        String img_url = appPreferences.getString("start_img", "");
        if (!img_url.equals("")) {
            Glide.with(this).load(img_url).placeholder(R.mipmap.splash_bg).into(iv_start_bg);
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                //app状态改为正常
                AppStatusManager.getInstance().setAppStatus(AppStatus.STATUS_NORMAL);
                startActivity(intent);
                finish();
            }
        }, 2000);
    }
}
